package com.earthchen.gps.dao;

import com.earthchen.gps.domain.GpsData;

import java.sql.SQLException;

/**
 * @author: EarthChen
 * @date: 2018/04/28
 */
public class GpsDao {


    /**
     * 保存gps数据
     *
     * @param gpsData
     * @return
     */
    public static boolean saveGpsData(GpsData gpsData) {
        String sql = "insert into gps_data (sn,isLocation, latitude, latitudeFlag, longitude, longitudeFlag, speed, direction, altitude, satelliteNumber, gmsSignalIntensity, power, stepNumber, rollNumber, terminalStatus, create_time) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
        DBHelper dbHelper = new DBHelper(sql);
        try {
            dbHelper.pst.setString(1, gpsData.getSn());
            dbHelper.pst.setString(2, gpsData.getIsLocation());
            dbHelper.pst.setString(3, gpsData.getLatitude());
            dbHelper.pst.setString(4, gpsData.getLatitudeFlag());
            dbHelper.pst.setString(5, gpsData.getLongitude());
            dbHelper.pst.setString(6, gpsData.getLongitudeFlag());
            dbHelper.pst.setDouble(7, gpsData.getSpeed());
            dbHelper.pst.setDouble(8, gpsData.getDirection());
            dbHelper.pst.setDouble(9, gpsData.getAltitude());
            dbHelper.pst.setInt(10, gpsData.getSatelliteNumber());
            dbHelper.pst.setInt(11, gpsData.getGmsSignalIntensity());
            dbHelper.pst.setInt(12, gpsData.getPower());
            dbHelper.pst.setInt(13, gpsData.getStepNumber());
            dbHelper.pst.setInt(14, gpsData.getRollNumber());
            dbHelper.pst.setString(15, gpsData.getTerminalStatus());
            dbHelper.pst.setTimestamp(16, new java.sql.Timestamp(gpsData.getCreateTime().getTime()));
            int success = dbHelper.pst.executeUpdate();
            return success > 0;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            dbHelper.close();
        }
        return false;
    }

}
